home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / utility / lsv15.zip / LS.PAS < prev   
Pascal/Delphi Source File  |  1996-06-12  |  4KB  |  136 lines

  1. program ls;
  2.  
  3. uses dos;
  4.  
  5. const months:array[1..12] of string[3]=
  6.       ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
  7.  
  8. var f:file;
  9.     homedr,sizes,fname:string;
  10.     i:integer;
  11.     dt:searchrec;
  12.     att:byte;
  13.     tempatt:byte;
  14.     diratt,writeatt,execatt,sysatt:boolean;
  15.     ytemp,mtemp,dtemp,wtemp:word;
  16.     tempst:string;
  17.     timel:longint;
  18.     times,ttemp,dates:string;
  19.     dq:datetime;
  20.     tempint:integer;
  21.  
  22. procedure outputline(dirb,rb,wb,xb,sb:boolean;size,date,time,name:string);
  23. var bigstr:string;
  24.     temp:string;
  25.     i:integer;
  26.     
  27. procedure stradd;
  28. begin
  29.   write(temp);
  30. end;
  31.  
  32. begin
  33.   bigstr:='';
  34.   if dirb then temp:='d' else temp:='-';
  35.   stradd;
  36.   for i:=1 to 3 do begin
  37.     if rb then temp:='r' else temp:='-';
  38.     stradd;
  39.     if wb then temp:='w' else temp:='-';
  40.     stradd;
  41.     if xb then temp:='x' else temp:='-';
  42.     stradd;
  43.   end;
  44.   if sb=true then
  45.      temp:='    1 root    user'
  46.   else
  47.      temp:='    1 root    sys ';
  48.   stradd;
  49.   for i:=1 to (12-length(size)) do write(' ');
  50.   write(size);
  51.   write(' ',date,' ',time,' ',name);
  52.   writeln;
  53. end;
  54.  
  55. function checkatt(att2,check:byte):boolean;
  56. var tempatt:byte;
  57. begin
  58.   tempatt:=(att2 and check);
  59.   if tempatt=check then checkatt:=true else checkatt:=false;
  60. end;
  61.  
  62. begin
  63.  if paramcount<>0 then begin
  64.     homedr:=paramstr(paramcount);
  65.     if ((length(homedr)<3) and (homedr[2]=':')) then begin
  66.        tempint:=ord(homedr[1])-64;
  67.        if tempint>26 then tempint:=tempint-32;
  68.        if tempint>26 then halt(0);
  69.        getdir(tempint,homedr);
  70.        if length(homedr)>3 then homedr:=concat(homedr,'\*.*');
  71.        if length(homedr)<4 then homedr:=concat(homedr,'*.*');
  72.     end;
  73.  end;
  74.  if paramcount=0 then begin
  75.    getdir(0,homedr);
  76.    if length(homedr)>3 then homedr:=concat(homedr,'\');
  77.    homedr:=concat(homedr,'*.*');
  78.  end;
  79.    Findfirst(homedr,AnyFile,dt);
  80.  while doserror=0 do begin
  81.    str(dt.size,sizes);
  82.    execatt:=false;
  83.    att:=(dt.attr);
  84.      if checkatt(att,$10) then begin
  85.         diratt:=true;
  86.         execatt:=true;
  87.      end
  88.      else begin
  89.         diratt:=false;
  90.         execatt:=false;
  91.      end;
  92.  
  93.      if checkatt(att,$01) then
  94.         writeatt:=false else writeatt:=true;
  95.  
  96.      if checkatt(att,$04) then
  97.         sysatt:=false else sysatt:=true;
  98.  
  99.      fname:=dt.name;
  100.    att:=dt.attr;
  101.      if checkatt(att,$02) then
  102.         fname:=concat('.',fname);
  103.    for i:=1 to length(fname) do
  104.        if ((fname[i]>='A') and (fname[i]<='Z'))
  105.           then fname[i]:=chr(ord(fname[i])+32);
  106.  
  107.    if length(fname)>3 then begin
  108.       tempst:=copy(fname,length(fname)-3,4);
  109.       if ((tempst='.exe') or (tempst='.bat') or (tempst='.com'))
  110.          then execatt:=true;
  111.    end;
  112.     timel:=dt.time;
  113.      times:='';
  114.      unpacktime(timel,dq);
  115.      str(dq.hour,ttemp);
  116.      if length(ttemp)<2 then ttemp:=concat(' ',ttemp);
  117.      times:=concat(times,ttemp);
  118.      str(dq.min,ttemp);
  119.      if length(ttemp)<2 then ttemp:=concat('0',ttemp);
  120.      getdate(ytemp,mtemp,dtemp,wtemp);
  121.      times:=concat(times,':',ttemp);
  122.      if ytemp<>dq.year then begin
  123.         str(dq.year,ttemp);
  124.         times:=concat(' ',ttemp);
  125.      end;
  126.      dates:=months[dq.month];
  127.      str(dq.day,ttemp);
  128.      if length(ttemp)<2 then ttemp:=concat(' ',ttemp);
  129.      dates:=concat(dates,' ',ttemp);
  130.  
  131.    {attrib searchrec}
  132.    outputline(diratt,true,writeatt,execatt,sysatt,sizes,dates,times,fname);
  133.    findnext(dt);
  134.  end;
  135.    writeln(homedr);
  136. end.